/**
 * PartyDao.java
 * com.jzwl.site.wap.party.dao
 * Copyright (c) 2019, 北京聚智未来科技有限公司版权所有.
*/

package com.jzwl.site.wap.party.dao;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.jzwl.common.constant.Constants;
import com.jzwl.system.base.dao.BaseDAO;

/**
 * @author   gyp
 * @Date	 2019年5月12日 	 
 */
@Repository("partyDao")
public class PartyDao {

	@Autowired
	private BaseDAO baseDAO;

	@Autowired
	private Constants constants;

	/**
	 * 获取党务建设首页数据
	 */
	public List queryByType(String type, boolean isPage) {
		String sql = "select t.articleId,t.nodeId,t.title,t.picLink,t.subtitle,t.seeNum,(select count(sauf.articleId) from site_article_user_fabulous sauf where sauf.articleId = t.articleId) as fabulousNum from "
				+ constants.getCurrentDB()
				+ "site_article t LEFT JOIN "
				+ constants.getCurrentDB()
				+ "site_node sn on t.nodeId = sn.id WHERE sn.redirectUrl = '"
				+ type
				+ "' and t.isDelete=0 and t.isPub=1 order by t.isTop desc, t.createTime desc ";
		if (isPage) {
			sql = sql + " limit 5";
		}
		return baseDAO.queryForList(sql);
	}

	public List queryNodeByType(String type, boolean isPage) {
		String sql = "select t.id,t.name,t.parentId,t.isRedirect,t.redirectUrl,t.isDisplay,t.imageUrl,t.ord from "
				+ constants.getCurrentDB() + "site_node t where t.parentId =  (select sn.id from "
				+ constants.getCurrentDB() + "site_node sn where sn.redirectUrl='" + type
				+ "') and t.isDelete = 0 ORDER BY t.ord asc;";
		if (isPage) {
			sql = sql + " limit 5";
		}
		return baseDAO.queryForList(sql);
	}

	/**
	 * 根据类型获取文章的内容
	 * @Date 2019年5月13日
	 * @author gyp
	 * @param type
	 * @return(这里描述每个参数,如果有返回值描述返回值,如果有异常描述异常)
	 */
	public Map queryArticleInfoByType(String type) {
		String sql = "select t.*,(select count(sauf.articleId) from site_article_user_fabulous sauf where sauf.articleId = t.articleId) as fabulousNum  from "
				+ constants.getCurrentDB()
				+ "site_article t LEFT JOIN "
				+ constants.getCurrentDB()
				+ "site_node sn on t.nodeId = sn.id WHERE sn.redirectUrl = '"
				+ type
				+ "' and t.isDelete=0 and t.isPub=1 order by t.isTop desc, t.createTime desc ";
		return baseDAO.queryForMap(sql);
	}

	/**
	 * 根据文章的Id获取文章的详细信息
	 * @param articleId
	 */
	public Map queryArticleInfoByArticleId(Map<String, Object> map) {
		String sql = "select t.*,(select count(sauf.articleId) from site_article_user_fabulous sauf where sauf.articleId = t.articleId) as fabulousNum  from "
				+ constants.getCurrentDB() + "site_article t where t.articleId =:articleId";
		return baseDAO.queryForMap(sql, map);
	}

	/**
	 * 更新查看的数量
	 * @param map
	 * @return TODO(这里描述每个参数,如果有返回值描述返回值,如果有异常描述异常)
	 */
	public boolean updateSeeNum(Map<String, Object> map) {
		String sql = "update " + constants.getCurrentDB() + "site_article set " + " seeNum = seeNum +1"
				+ " where articleId=:articleId";
		return baseDAO.executeNamedCommand(sql, map);
	}

}
